import time

from apscheduler.schedulers.asyncio import AsyncIOScheduler
from service.base import BaseCrawler

def start_scheduler():
    scheduler = AsyncIOScheduler()
    # 每小时执行一次：interval (每小时)
    scheduler.add_job(run_task, "interval", hours=1)

    # 每天凌晨 0 点执行：cron (每天)
    # scheduler.add_job(run_task, "cron", hour=0, minute=0)

    scheduler.start()
    print("定时任务启动成功：",time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))


async def run_task():
    crawler = BaseCrawler()
    await crawler.run()